-
Notifications
You must be signed in to change notification settings - Fork 15
/
Solution01.py
50 lines (40 loc) · 943 Bytes
/
Solution01.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# SOlution First
from collections import defaultdict
class Juspay_solution:
def solution(self):
visited = defaultdict(list)
def dfs_approach(s, e):
if s==e: return True
visited[s] = 1
for x in adj[s]:
if not visited[x]:
if dfs_approach(x, e):
return True
n = int(input())
participants = []
for i in range(n):
participants.append(int(input()))
no_of_adjacent = int(input())
adj = defaultdict(list)
for i in range(no_of_adjacent):
x, y = map(int, input().split())
adj[x].append(y)
n1 = int(input())
n2 = int(input())
if dfs_approach(n1, n2):
return 1
else:
return 0
print(Juspay_solution().solution())
# 4
# 2
# 5
# 7
# 9
# 4
# 2 9
# 7 2
# 7 9
# 9 5
# 7
# 9